package com.sc.pattern.activeobjects;

/**
 * Created  on 2018/1/14.
 *
 * @author sc
 */
public class FutureResult implements Result{
    private Result result;
    private boolean ready = false;

    public synchronized void setResult(Result result){
        this.result = result;
        this.ready  = true;
        this.notifyAll();
    }

    @Override
    public synchronized Object getResultValue() {
        while (!ready){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return this.result.getResultValue();
    }
}
